package vip.mall.modular.message.controller;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.mall.common.result.CommonResult;
import vip.mall.modular.comment.params.CommentPageParams;
import vip.mall.modular.message.entity.Message;
import vip.mall.modular.message.params.AddMessageParams;
import vip.mall.modular.message.service.MessageService;

/**
 * @author Asus
 * @Date 2025/2/10 15:23
 * @Descripition
 */
@RestController
@RequestMapping("/message")
@Tag(name = "消息模块控制器")
@Slf4j
public class MessageController {
    @Resource
    private MessageService messageService;

    @PostMapping("/add")
    @Operation(summary = "添加消息")
    public CommonResult addMessage(@RequestBody AddMessageParams addMessageParams) {
        if (ObjectUtil.isEmpty(addMessageParams)) {
            return CommonResult.error("添加失败");
        }
        boolean result = messageService.add(addMessageParams);
        return result ? CommonResult.success() : CommonResult.error();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除消息")
    public CommonResult deleteMessage(@RequestParam("id") String id) {
        boolean result = messageService.removeById(id);
        return result ? CommonResult.success() : CommonResult.error();
    }

    @PostMapping("/edit")
    @Operation(summary = "修改消息")
    public CommonResult editMessage(@RequestBody Message message) {
        boolean result = messageService.updateById(message);
        return result ? CommonResult.success() : CommonResult.error();
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取消息列表")
    public CommonResult pageMessage(@RequestBody CommentPageParams commentPageParams) {
        return CommonResult.success(messageService.pageList(commentPageParams));
    }
}
